package com.yanqu.road.entity.activity.eggs;

import com.alibaba.fastjson.JSON;
import com.yanqu.road.entity.DataObject;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class EggsUserData extends DataObject {
    private int activityId;                                                 //活动编号
    private long userId;                                                    //玩家编号
    private int curTestId;                                                  //当前问答题编号
    private boolean isTestReward;                                           //问答题是否领取奖励
    private int sceneEventNo;                                               //触发事件数
    private Map<Integer, EggsClassRoomData> classRoomDataMap = new ConcurrentHashMap<>();               //课堂数据
    private Map<Integer, EggsTestData> testDataMap = new ConcurrentHashMap<>();                         //问答题数据
    private Map<Integer, EggsSongData> songDataMap = new ConcurrentHashMap<>();                         //歌曲数据
    private Map<Integer, EggsStoryData> storyDataMap = new ConcurrentHashMap<>();                       //故事数据

    public int getActivityId() {
        return activityId;
    }

    public void setActivityId(int activityId) {
        if(this.activityId != activityId) {
            this.activityId = activityId;
            setUpdateOption();
        }
    }

    public long getUserId() {
        return userId;
    }

    public void setUserId(long userId) {
        if(this.userId != userId) {
            this.userId = userId;
            setUpdateOption();
        }
    }

    public int getCurTestId() {
        return curTestId;
    }

    public void setCurTestId(int curTestId) {
        if(this.curTestId != curTestId) {
            this.curTestId = curTestId;
            setUpdateOption();
        }
    }

    public boolean isTestReward() {
        return isTestReward;
    }

    public void setTestReward(boolean testReward) {
        if(isTestReward != testReward) {
            isTestReward = testReward;
            setUpdateOption();
        }
    }

    public int getSceneEventNo() {
        return sceneEventNo;
    }

    public void setSceneEventNo(int sceneEventNo) {
        if(this.sceneEventNo != sceneEventNo) {
            this.sceneEventNo = sceneEventNo;
            setUpdateOption();
        }
    }

    public Map<Integer, EggsClassRoomData> getClassRoomDataMap() {
        return classRoomDataMap;
    }
    public String getClassRoomDataMapJsonStr() {
        if(null == classRoomDataMap){
            return "{}";
        }else {
            return JSON.toJSONString(classRoomDataMap);
        }
    }

    public void setClassRoomDataMap(Map<Integer, EggsClassRoomData> classRoomDataMap) {
        this.classRoomDataMap = classRoomDataMap;
        setUpdateOption();
    }

    public boolean getClassRoomIsReward(int id){
        EggsClassRoomData eggsClassRoomData = classRoomDataMap.get(id);
        if(null == eggsClassRoomData){
            return false;
        }
        return eggsClassRoomData.isReward();
    }
    public void setClassRoomReward(int id){
        EggsClassRoomData eggsClassRoomData = classRoomDataMap.get(id);
        if(null == eggsClassRoomData){
            eggsClassRoomData = new EggsClassRoomData();
            eggsClassRoomData.setId(id);
            classRoomDataMap.put(id, eggsClassRoomData);
        }
        eggsClassRoomData.setReward(true);
        setUpdateOption();
    }

    public Map<Integer, EggsTestData> getTestDataMap() {
        return testDataMap;
    }
    public String getTestDataMapJsonStr() {
        if(null == testDataMap){
            return "{}";
        }else {
            return JSON.toJSONString(testDataMap);
        }
    }

    public void setTestDataMap(Map<Integer, EggsTestData> testDataMap) {
        this.testDataMap = testDataMap;
        setUpdateOption();
    }

    public int getTestChoose(int id){
        EggsTestData eggsTestData = testDataMap.get(id);
        if(null == eggsTestData){
            return 0;
        }
        return eggsTestData.getChoose();
    }
    public void setTestChoose(int id, int choose){
        EggsTestData eggsTestData = testDataMap.get(id);
        if(null == eggsTestData){
            eggsTestData = new EggsTestData();
            eggsTestData.setId(id);
            testDataMap.put(id, eggsTestData);
        }
        eggsTestData.setChoose(choose);
        setUpdateOption();
    }

    public Map<Integer, EggsSongData> getSongDataMap() {
        return songDataMap;
    }
    public String getSongDataMapJsonStr() {
        if(null == songDataMap){
            return "{}";
        }else {
            return JSON.toJSONString(songDataMap);
        }
    }

    public void setSongDataMap(Map<Integer, EggsSongData> songDataMap) {
        this.songDataMap = songDataMap;
        setUpdateOption();
    }

    public boolean getSongIsReward(int id){
        EggsSongData eggsSongData = songDataMap.get(id);
        if(null == eggsSongData){
            return false;
        }
        return eggsSongData.isReward();
    }
    public void setSongReward(int id){
        EggsSongData eggsSongData = songDataMap.get(id);
        if(null == eggsSongData){
            eggsSongData = new EggsSongData();
            eggsSongData.setId(id);
            songDataMap.put(id, eggsSongData);
        }
        eggsSongData.setReward(true);
        setUpdateOption();
    }

    public Map<Integer, EggsStoryData> getStoryDataMap() {
        return storyDataMap;
    }
    public String getStoryDataMapJsonStr() {
        if(null == storyDataMap){
            return "{}";
        }else {
            return JSON.toJSONString(storyDataMap);
        }
    }

    public void setStoryDataMap(Map<Integer, EggsStoryData> storyDataMap) {
        this.storyDataMap = storyDataMap;
        setUpdateOption();
    }

    public boolean getStoryIsReward(int id){
        EggsStoryData eggsStoryData = storyDataMap.get(id);
        if(null == eggsStoryData){
            return false;
        }
        return eggsStoryData.isReward();
    }
    public void setStoryReward(int id){
        EggsStoryData eggsStoryData = storyDataMap.get(id);
        if(null == eggsStoryData){
            eggsStoryData = new EggsStoryData();
            eggsStoryData.setId(id);
            storyDataMap.put(id, eggsStoryData);
        }
        eggsStoryData.setReward(true);
        setUpdateOption();
    }
}
